package com.lvy.hczn.front.business.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lvy.hczn.front.business.common.Constants;
import com.lvy.hczn.front.business.dto.Param;
import com.lvy.hczn.front.business.service.AccessManagerService;
import com.lvy.hczn.front.business.service.GoodsBoxService;
import com.lvy.hczn.front.business.service.SaleOrderService;
import com.lvy.hczn.front.common.constant.MqConstants;
import com.lvy.hczn.front.common.constant.RedisConstants;
import com.lvy.hczn.front.common.core.domain.BaseModel;
import com.lvy.hczn.front.common.utils.DictUtils;
import com.lvy.hczn.front.system.domain.business.*;
import com.lvy.hczn.front.business.mapper.WarehousingEntryMapper;
import com.lvy.hczn.front.system.domain.business.dto.*;
import com.lvy.hczn.front.system.service.*;
import com.lvy.hczn.front.business.service.WarehousingEntryService;
import com.lvy.hczn.front.common.core.redis.RedisCache;
import com.lvy.hczn.front.common.exception.UtilException;
import com.lvy.hczn.mq.rocket.ParamInfo;
import com.lvy.hczn.mq.rocket.ProducerUtil;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class WarehousingEntryServiceImpl extends ServiceImpl<WarehousingEntryMapper, WarehousingEntry> implements WarehousingEntryService {

    @Autowired
    private WarehousingEntryMapper warehousingEntryMapper;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private SpuService spuService;

    @Autowired
    private ProducerUtil producerUtil;

    @Autowired
    private WarehouseService warehouseService;

    @Autowired
    private AccessManagerService accessManagerService;

    @Autowired
    private TemperatureZoneService temperatureZoneService;

    @Autowired
    private DataExceptionDetailService dataExceptionDetailService;

    @Autowired
    private DataExceptionService dataExceptionService;

    @Autowired
    private GoodsBoxService goodsBoxService;
    @Autowired
    private IParcelService parcelService;
    @Autowired
    private SaleOrderService saleOrderService;

    /**
     * 入库单及状态查询
     *
     * @param entryCode
     * @param status
     * @param clientId
     * @param deliveryOrderCode
     * @return com.lvy.hczn.model.order.WarehousingEntry
     * @author yw
     * @date 2022-05-08 15:08:58
     */
    @Override
    @Deprecated
    public WarehousingEntry selectByEntryCodeAndStatus(String entryCode, String status, String clientId, String deliveryOrderCode) throws Exception {
        if (StrUtil.isEmpty(entryCode)) {
            throw new UtilException("入库单为空");
        }
        WarehousingEntry warehousingEntry = super.getOne(Wrappers.<WarehousingEntry>lambdaQuery().eq(WarehousingEntry::getEntryCode, entryCode).eq(WarehousingEntry::getStatus, status));
        if (warehousingEntry == null) {
            throw new UtilException("入库信息为空");
        }
        Spu spu = spuService.getOne(Wrappers.<Spu>lambdaQuery().eq(Spu::getSpuCode, warehousingEntry.getSpuId()));
        if (spu != null) {
            warehousingEntry.setTemperatureZoneCode(spu.getTemperatureZoneCode());
        }
        return warehousingEntry;
    }

    /**
     * 入库单及状态查询
     *
     * @param entryCode
     * @param status
     * @param clientId
     * @param deliveryOrderCode
     * @return com.lvy.hczn.model.order.WarehousingEntry
     * @author yw
     * @date 2022-05-08 15:08:58
     */
    @Override
    public List<WarehousingEntry> selectByEntryCodeAndStatusList(String entryCode, String status, String clientId, String deliveryOrderCode) throws Exception {
        if (StrUtil.isEmpty(deliveryOrderCode)) {
            throw new UtilException("入库单为空");
        }
        List<String> dataTypes = new ArrayList<>();
        dataTypes.add(com.lvy.hczn.front.common.constant.Constants.WAREHOUSING_ENTRY_DATA_TYPE_ONE);
        dataTypes.add(com.lvy.hczn.front.common.constant.Constants.WAREHOUSING_ENTRY_DATA_TYPE_TWO);
        dataTypes.add(com.lvy.hczn.front.common.constant.Constants.WAREHOUSING_ENTRY_DATA_TYPE_THREE);
        dataTypes.add(com.lvy.hczn.front.common.constant.Constants.WAREHOUSING_ENTRY_DATA_TYPE_FOUR);
        dataTypes.add(com.lvy.hczn.front.common.constant.Constants.WAREHOUSING_ENTRY_DATA_TYPE_TWELVE);
        dataTypes.add(com.lvy.hczn.front.common.constant.Constants.WAREHOUSING_ENTRY_DATA_TYPE_THIRTEEN);
        List<WarehousingEntry> list = super.list(Wrappers.<WarehousingEntry>lambdaQuery().eq(WarehousingEntry::getEntryCode, deliveryOrderCode).in(WarehousingEntry::getDataType, dataTypes).eq(WarehousingEntry::getStatus, status));
        if (list.isEmpty()) {
            throw new UtilException("入库信息为空");
        }
        String bgPrefix = DictUtils.getDictValue(com.lvy.hczn.front.common.constant.Constants.SYS_DICT_ORDER_TYPE, com.lvy.hczn.front.common.constant.Constants.SYS_DICT_ORDER_TYPE_BG);
        if (deliveryOrderCode.startsWith(bgPrefix)) {
            list = super.list(Wrappers.<WarehousingEntry>lambdaQuery().eq(WarehousingEntry::getBoxCode, list.get(0).getBoxCode()).eq(WarehousingEntry::getStatus, status));
        }
        list.forEach(warehousingEntry -> {
            Spu spu = spuService.getOne(Wrappers.<Spu>lambdaQuery().eq(Spu::getSpuCode, warehousingEntry.getSpuId()));
            if (spu != null) {
                warehousingEntry.setTemperatureZoneCode(spu.getTemperatureZoneCode());
            }
        });
        return list;
    }

    @Override
    public List<WarehousingEntry> selectByEntryCodeAndStatusList(String entryCode, String status) {
        List<WarehousingEntry> list = super.list(Wrappers.<WarehousingEntry>lambdaQuery().eq(WarehousingEntry::getEntryCode, entryCode).eq(WarehousingEntry::getStatus, status));
        if (list.isEmpty()) {
            throw new UtilException("入库信息为空");
        }
        list.forEach(warehousingEntry -> {
            Spu spu = spuService.getOne(Wrappers.<Spu>lambdaQuery().eq(Spu::getSpuCode, warehousingEntry.getSpuId()));
            if (spu != null) {
                warehousingEntry.setTemperatureZoneCode(spu.getTemperatureZoneCode());
            }
        });
        return list;
    }

    /**
     * 入库单推送到平台
     * 入库单以规格列表展示，即：以一个仓库下的一个运输/配送单下的一个供应商的一个商品的一个规格，区分货箱列表展示（规格下的存放的哪几个货箱）
     * 以供应商区分的map案列,实际以列表推送即可
     * {"210831090516920208":[{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"5","spuCode":"4","specId":"157169367745216","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"210831090516920208","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"5","weight":6.27,"operator":"anonymousUser"},{"quantity":1,"boxNum":1,"boxCode":"7","weight":6.27,"operator":"anonymousUser"}]},{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"5","spuCode":"4","specId":"1571699727452161","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"210831090516920208","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"5","weight":6.27,"operator":"anonymousUser"}]},{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"4","spuCode":"4","specId":"157169367727452161","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"210831090516920208","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"4","weight":6.27,"operator":"anonymousUser"}]}],"210831090516992066":[{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"1","spuCode":"6","specId":"1571693679366742011","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"210831090516992066","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"1","weight":6.27,"operator":"anonymousUser"}]}],"2831090516992020877":[{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"1","spuCode":"9","specId":"1571693679727452162","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"2831090516992020877","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"1","weight":6.27,"operator":"anonymousUser"},{"quantity":1,"boxNum":1,"boxCode":"8","weight":6.27,"operator":"anonymousUser"}]}],"2108310905169920":[{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"3","spuCode":"3","specId":"157169367936674201","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"2108310905169920","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"3","weight":6.27,"operator":"anonymousUser"}]},{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"1","spuCode":"3","specId":"1571693679366742017","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"2108310905169920","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"1","weight":6.27,"operator":"anonymousUser"}]}],"2108310905169920208":[{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"2","spuCode":"7","specId":"1571693679366742015","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"2108310905169920208","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"2","weight":6.27,"operator":"anonymousUser"}]}]}
     * <p>
     * 列表形式：
     * [{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"5","spuCode":"4","specId":"157169367745216","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"210831090516920208","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"5","weight":6.27,"operator":"anonymousUser"},{"quantity":1,"boxNum":1,"boxCode":"7","weight":6.27,"operator":"anonymousUser"}]},{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"5","spuCode":"4","specId":"1571699727452161","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"210831090516920208","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"5","weight":6.27,"operator":"anonymousUser"}]},{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"4","spuCode":"4","specId":"157169367727452161","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"210831090516920208","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"4","weight":6.27,"operator":"anonymousUser"}]},{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"1","spuCode":"6","specId":"1571693679366742011","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"210831090516992066","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"1","weight":6.27,"operator":"anonymousUser"}]},{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"1","spuCode":"9","specId":"1571693679727452162","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"2831090516992020877","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"1","weight":6.27,"operator":"anonymousUser"},{"quantity":1,"boxNum":1,"boxCode":"8","weight":6.27,"operator":"anonymousUser"}]},{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"3","spuCode":"3","specId":"157169367936674201","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"2108310905169920","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"3","weight":6.27,"operator":"anonymousUser"}]},{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"1","spuCode":"3","specId":"1571693679366742017","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"2108310905169920","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"1","weight":6.27,"operator":"anonymousUser"}]},{"associatedOrderCode":"CGD1571693678477549568","type":"1","boxCode":"2","spuCode":"7","specId":"1571693679366742015","batchCode":"1571693679366742016","quantity":1,"weight":6.27,"supplierId":"2108310905169920208","producerId":"2108310905169920208","createBy":"anonymousUser","entryBoxDtoList":[{"quantity":1,"boxNum":1,"boxCode":"2","weight":6.27,"operator":"anonymousUser"}]}]
     *
     * @param warehousingEntry
     * @return void
     * @author yw
     * @date 2023-05-27 20:11:00
     */
    @Override
    public synchronized void commitToPlatform(WarehousingEntry warehousingEntry, boolean sortDone, boolean shelfLocation) {
        if (StrUtil.isEmpty(warehousingEntry.getEntryCode())) {
            throw new UtilException("入库单号为空");
        }
        if (StrUtil.isEmpty(warehousingEntry.getServiceCode())) {
            throw new UtilException("业务单号为空");
        }
        /*if (warehousingEntry.getDataType() == null) {
            throw new UtilException("数据类型为空");
        }
        if (warehousingEntry.getServiceType() == null) {
            throw new UtilException("业务类型为空");
        }*/
        Warehouse warehouse = warehouseService.selectLocalWarehouseFront();
        if (warehouse == null) {
            throw new UtilException("前置仓库为空");
        }
        warehousingEntry.setWarehouseCode(warehouse.getWarehouseCode());
        List<WarehousingEntry> list = warehousingEntryMapper.commitToPlatform(warehousingEntry);
        String bgPrefix = DictUtils.getDictValue(com.lvy.hczn.front.common.constant.Constants.SYS_DICT_ORDER_TYPE, com.lvy.hczn.front.common.constant.Constants.SYS_DICT_ORDER_TYPE_BG);
        /*包裹数据提交*/
        if (warehousingEntry.getEntryCode().startsWith(bgPrefix)) {
            this.commitToPlatformOfParcel(list, sortDone, shelfLocation);
            return;
        }

        if (!list.isEmpty()) {
            List<WarehousingEntryDto> enDtoList = JSONUtil.toList(JSONUtil.toJsonStr(list), WarehousingEntryDto.class);
            /**发送到数据转发中心**/
            String tag = MqConstants.TAG_WAREHOUSE_ENTRY;

            //dataType分组
            LinkedHashMap<String, List<WarehousingEntryDto>> mapDataType = enDtoList.stream().collect(Collectors.groupingBy(WarehousingEntryDto::getDataType, LinkedHashMap::new, Collectors.toList()));
            mapDataType.forEach((dataTypeKey, dataTypeValues) -> {
                //根据供应商分组
                LinkedHashMap<String, List<WarehousingEntryDto>> mapSupplier = dataTypeValues.stream().collect(Collectors.groupingBy(WarehousingEntryDto::getSupplierCode, LinkedHashMap::new, Collectors.toList()));

                Map<String, List<WarehousingEntryDto>> map = new HashMap<>();
                List<WarehousingEntryDto> entryList = new ArrayList<>();
                /**供应商下的spu下的规格以货箱为单位展现，即：规格存放在多个货箱中**/
                Map<String, Object> objectMap = new HashMap<>();
                mapSupplier.forEach((key, value) -> {
                    if (!value.isEmpty()) {
                        List<WarehousingEntryDto> entryDtoList = new ArrayList<>();
                        //根据spu分组
                        LinkedHashMap<String, List<WarehousingEntryDto>> mapSpu = value.stream().collect(Collectors.groupingBy(WarehousingEntryDto::getSpuId, LinkedHashMap::new, Collectors.toList()));
                        mapSpu.forEach((mapSpuKey, mapSpuValue) -> {
                            //根据规格分组
                            LinkedHashMap<String, List<WarehousingEntryDto>> mapSpec = mapSpuValue.stream().collect(Collectors.groupingBy(WarehousingEntryDto::getSpecCode, LinkedHashMap::new, Collectors.toList()));
                            initData(mapSpec, entryDtoList, objectMap);
                        });
                        map.put(key, entryDtoList);
                    }
                });
                log.info("map->" + JSONUtil.toJsonStr(map));
                map.forEach((k, v) -> {
                    entryList.addAll(v);
                });
                log.info("list->" + JSONUtil.toJsonStr(entryList));

                if (!entryList.isEmpty()) {
                    try {
                        ParamInfo<WarehousingEntryDto> info = new ParamInfo<>();
                        info.setTicketType(String.valueOf(objectMap.get("dataType")));
                        info.setList(entryList);
                        info.setWarehouseCode(warehouse.getWarehouseCode());
                        log.error("commitToPlatform:{}", JSON.toJSONString(info));
                        producerUtil.sendAsyncMsg(MqConstants.TOPIC_WAREHOUSE_AREA, tag, JSON.toJSONStringWithDateFormat(info, JSON.DEFFAULT_DATE_FORMAT).getBytes(StandardCharsets.UTF_8), IdUtil.fastSimpleUUID());
                        list.forEach(entry -> {
                            entry.setStatus(Constants.ENTRY_ED);
                            super.updateById(entry);
                        });
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            });

            if (!sortDone) {
                //发送入仓通知到平台
                ThreadUtil.execAsync(() -> {
                    entryMsg(list.get(0), false);
                });
            }

            if (shelfLocation) {
                //出入库库位调整
                ThreadUtil.execAsync(() -> {
                    boxShelfLocationMsg(list, null, false);
                });
            }
        }

    }

    /**
     * 包裹数据提交
     *
     * @param list
     * @return void
     * @author yw
     * @date 2023-08-25 10:29:26
     */
    public void commitToPlatformOfParcel(List<WarehousingEntry> list, boolean sortDone, boolean shelfLocation) {

        if (CollUtil.isNotEmpty(list)) {
            // 按照仓库分组
            Map<String, List<WarehousingEntry>> listMap = list.stream().collect(Collectors.groupingBy(WarehousingEntry::getWarehouseCode));
            listMap.forEach((warehouseCode, entrys) -> {
                WarehouseParcelDto warehouseParcelDto = new WarehouseParcelDto();
                warehouseParcelDto.setWarehouseCode(warehouseCode);

                List<WarehouseParcelDetailDto> warehouseParcelDetailDtos = new ArrayList<>();

                Map<String, List<WarehousingEntry>> dataTypeMap = entrys.stream().collect(Collectors.groupingBy(WarehousingEntry::getDataType));

                dataTypeMap.forEach((dataType, entryList) -> {
                    warehouseParcelDto.setTicketType(dataType);
                    List<WarehousingEntry> warehousingEntryListInfo = new ArrayList<>();
                    for (WarehousingEntry entry : entryList) {
                        warehouseParcelDto.setTicketType(dataType);
                        Parcel parcel = parcelService.getOne(Wrappers.<Parcel>lambdaQuery().eq(Parcel::getParcelNo, entry.getAssociatedOrderCode()));

                        List<ParcelDetailDto> parcelList = JSONUtil.toList(parcel.getParcelDetail(), ParcelDetailDto.class);
                        Warehouse currentWarehouse = warehouseService.selectLocalWarehouseFront();
                        LocalDateTime sortDate = LocalDateTime.now();
                        if (currentWarehouse.getWarehouseCode().equals(parcel.getTargetWarehouseCode())) {
                            var saleOrder = saleOrderService.getOne(Wrappers.lambdaQuery(SaleOrder.class).eq(SaleOrder::getSaleOrderCode, parcel.getParcelNo()));
                            if (Objects.nonNull(saleOrder) && Objects.isNull(saleOrder.getDeliveryTime())) {
                                SaleOrder saleOrder1 = new SaleOrder();
                                saleOrder1.setSaleOrderCode(parcel.getParcelNo());
                                saleOrder1.setId(saleOrder.getId());
                                // 包裹可能没有派送时间.那么派送时间就以送达时间为准
                                // 当前时间必须是早上8点 到 下午 18点前
                                var nowTime = LocalDateTime.now();
                                var hours = nowTime.getHour();
                                int start = redisCache.getCacheObject(RedisConstants.BG_TIME_START);
                                int end = redisCache.getCacheObject(RedisConstants.BG_TIME_END);
                                if (hours >= start && hours <= end) {
                                    sortDate = nowTime.plusMinutes(60);
                                    saleOrder1.setDeliveryTime(sortDate);
                                } else {
                                    sortDate = nowTime.plusDays(1).withHour(8);
                                    //如果时间超过18点.那么推迟到第二天早上8点分拣
                                    saleOrder1.setDeliveryTime(sortDate);
                                }
                                saleOrderService.updateById(saleOrder1);
                            }
                        }
                        //todo 包裹入库同箱，目前中台那边是按照一个包裹推送，只能根据包裹单号入库，所以需要根据入库的包裹单号的货箱，查询货箱内其他包裹单号，全部推送到中台
                        //                            * 之后重构调整为，中台揽件时，一个或多个货箱生成配送单，即配送单->货箱列表->包裹列表的接口数据格式
                        if (dataType.equals(com.lvy.hczn.front.common.constant.Constants.WAREHOUSING_ENTRY_DATA_TYPE_THIRTEEN)) {
                            warehouseParcelDto.setSortDate(sortDate);
                            List<WarehousingEntry> warehousingEntryList = super.list(Wrappers.<WarehousingEntry>lambdaQuery().eq(WarehousingEntry::getBoxCode, parcel.getCartonCode()).eq(WarehousingEntry::getStatus, Constants.ENTRY_ING));
                            Map<String, List<WarehousingEntry>> entryCodeMap = warehousingEntryList.stream().collect(Collectors.groupingBy(WarehousingEntry::getEntryCode));
                            LocalDateTime finalSortDate = sortDate;
                            entryCodeMap.forEach((entryCode, entryCodeList) -> {
                                Parcel tmp = parcelService.getOne(Wrappers.<Parcel>lambdaQuery().eq(Parcel::getParcelNo, entryCode));
                                var saleOrder = saleOrderService.getOne(Wrappers.lambdaQuery(SaleOrder.class).eq(SaleOrder::getSaleOrderCode, tmp.getParcelNo()));
                                if (Objects.nonNull(saleOrder) && Objects.isNull(saleOrder.getDeliveryTime())) {
                                    saleOrder.setDeliveryTime(finalSortDate);
                                    saleOrderService.updateById(saleOrder);
                                }
                                List<ParcelDetailDto> parcelListInfo = JSONUtil.toList(tmp.getParcelDetail(), ParcelDetailDto.class);
                                for (ParcelDetailDto parcelDetailDto : parcelListInfo) {
                                    WarehouseParcelDetailDto detailDto = new WarehouseParcelDetailDto();
                                    detailDto.setParcelNo(tmp.getParcelNo());
                                    detailDto.setCartonCode(parcelDetailDto.getCartonCode());
                                    detailDto.setTemperId(parcelDetailDto.getTemperId());
                                    detailDto.setContainerId(parcelDetailDto.getContainerId());
                                    detailDto.setCargoId(parcelDetailDto.getCargoId());
                                    detailDto.setWeight(parcelDetailDto.getWeight());
                                    detailDto.setVolume(parcelDetailDto.getVolume());
                                    warehouseParcelDetailDtos.add(detailDto);
                                }
                                warehousingEntryListInfo.addAll(entryCodeList);
                            });
                        } else {
                            for (ParcelDetailDto parcelDetailDto : parcelList) {
                                WarehouseParcelDetailDto detailDto = new WarehouseParcelDetailDto();
                                detailDto.setParcelNo(parcel.getParcelNo());
                                detailDto.setCartonCode(parcelDetailDto.getCartonCode());
                                detailDto.setTemperId(parcelDetailDto.getTemperId());
                                detailDto.setContainerId(parcelDetailDto.getContainerId());
                                detailDto.setCargoId(parcelDetailDto.getCargoId());
                                detailDto.setWeight(parcelDetailDto.getWeight());
                                detailDto.setVolume(parcelDetailDto.getVolume());
                                warehouseParcelDetailDtos.add(detailDto);
                            }
                        }


                    }
                    warehouseParcelDto.setList(warehouseParcelDetailDtos);

                    // 发送消息到数据转发中心
                    try {
                        list.forEach(entry -> {
                            entry.setStatus(Constants.ENTRY_ED);
                            super.updateById(entry);
                        });
                        if (!warehousingEntryListInfo.isEmpty()) {
                            warehousingEntryListInfo.forEach(entry -> {
                                entry.setStatus(Constants.ENTRY_ED);
                                super.updateById(entry);
                            });
                        }
                        producerUtil.sendAsyncMsg(MqConstants.TOPIC_ARRIVE, MqConstants.TOPIC_ARRIVE_TAG_PARCEL_ENTRY, JSON.toJSONStringWithDateFormat(warehouseParcelDto, JSON.DEFFAULT_DATE_FORMAT).getBytes(StandardCharsets.UTF_8), IdUtil.fastSimpleUUID());
                    } catch (Exception e) {
                        throw new UtilException(e);
                    }
                });
            });

               /* if (!sortDone) {
                    //发送入仓通知到平台
                    ThreadUtil.execAsync(() -> {
                        entryMsg(list.get(0), false);
                    });
                }*/

            if (shelfLocation) {
                //出入库库位调整
                ThreadUtil.execAsync(() -> {
                    boxShelfLocationMsg(list, null, false);
                });
            }
        }
    }

    /**
     * 货物运输单货配送单全部货箱入仓完成后，发送通知到平台
     *
     * @param warehousingEntry
     * @return void
     * @author yw
     * @date 2023-08-25 10:29:26
     */
    public void entryMsg(WarehousingEntry warehousingEntry, boolean access) {
        AccessManager accessManager = accessManagerService.getOne(Wrappers.<AccessManager>lambdaQuery().eq(AccessManager::getAccessCode, warehousingEntry.getAssociatedOrderCode()).orderByDesc(BaseModel::getCreateTime).last("limit 1"));
        if (accessManager != null) {
            accessManager.setSourceCode(warehousingEntry.getServiceCode());
            accessManagerService.accessManagerCode(accessManager, access);
        } else {
            log.error("未找到门禁编码：{}", warehousingEntry.getAssociatedOrderCode());
        }

    }

    /**
     * 货箱出入库库位变更通知
     * 此方法两个场景，一个是单据出入库，另一个是仓库空箱出库或者指定货箱出库
     * 根据参数warehouse，如果是仓库指定出库，则无dataType
     *
     * @param list
     * @return void
     * @author yw
     * @date 2023-09-27 10:47:22
     */
    @Override
    public synchronized void boxShelfLocationMsg(List<WarehousingEntry> list, List<GoodsBox> goodsBoxList, boolean isWarehouse) {
        Warehouse warehouse = warehouseService.selectLocalWarehouseFront();
        if (warehouse != null) {
            ParamInfo info = new ParamInfo<>();
            info.setWarehouseCode(warehouse.getWarehouseCode());
            List<ShelfLocationGoodsBoxDto> locationGoodsBoxDtos = new ArrayList<>();
            if (isWarehouse) {
                /**仓库指定**/
                //仓库内部出入货箱调整，比如，分拣变成空箱，地平仓迁移到货架
                if (goodsBoxList != null && !goodsBoxList.isEmpty()) {
                    info.setIntStorage(goodsBoxList.get(0).isIntStorage());
                    if (goodsBoxList.get(0).isIntStorage()) {
                        //地平仓大件商品迁移到货架
                        info.setType(com.lvy.hczn.front.common.constant.Constants.SHELF_LOCATION_ENTRY);
                    } else {
                        info.setType(com.lvy.hczn.front.common.constant.Constants.SHELF_LOCATION_OUT);
                    }
                    goodsBoxList.forEach(goodsBox -> {
                        initShelfLocationGoodsBoxDto(goodsBox, locationGoodsBoxDtos, null);
                    });
                }
            } else {
                //发货,调拨,补货,运输出入库
                /**需指定是货箱出入库的DataType，然后去货箱编号**/
                if (!list.isEmpty()) {
                    List<String> dataTypeList = com.lvy.hczn.front.common.constant.Constants.entryDataTypeList();
                    Map<String, String> map = dataTypeList.stream().collect(Collectors.toMap(item -> String.valueOf(item), item -> item.toString()));
                    if (map.containsKey(list.get(0).getDataType())) {
                        //采购入库
                        info.setType(com.lvy.hczn.front.common.constant.Constants.SHELF_LOCATION_ENTRY);
                    } else if (com.lvy.hczn.front.common.constant.Constants.WAREHOUSING_ENTRY_DATA_TYPE_NINE.equals(list.get(0).getDataType()) || "BGCK".equals(list.get(0).getDataType())) {
                        //调拨出库
                        info.setType(com.lvy.hczn.front.common.constant.Constants.SHELF_LOCATION_OUT);
                    }
                    //货箱分组
                    LinkedHashMap<String, List<WarehousingEntry>> mapWarehousingEntry = list.stream().filter(item -> !StrUtil.isEmpty(item.getBoxCode())).collect(Collectors.groupingBy(WarehousingEntry::getBoxCode, LinkedHashMap::new, Collectors.toList()));
                    if (mapWarehousingEntry != null && !map.isEmpty()) {
                        mapWarehousingEntry.forEach((k, v) -> {
                            if (v != null && !v.isEmpty()) {
                                GoodsBox goodsBox = goodsBoxService.getOne(Wrappers.<GoodsBox>lambdaQuery().eq(GoodsBox::getBoxCode, k));
                                if (goodsBox != null) {
                                    //代替一下
                                    initShelfLocationGoodsBoxDto(goodsBox, locationGoodsBoxDtos, v.get(0).getSpuId());
                                }
                            }

                        });
                    }
                }
            }
            if (!locationGoodsBoxDtos.isEmpty()) {
                String tag = MqConstants.TAG_WAREHOUSE_SHELF_LOCATION;
                info.setList(locationGoodsBoxDtos);
                info.setWarehouseCode(warehouse.getWarehouseCode());
                log.error("库位调整发送参数:{}", JSON.toJSONString(info));
                try {
                    producerUtil.sendAsyncMsg(MqConstants.TOPIC_WAREHOUSE_AREA, tag, JSON.toJSONString(info).getBytes(StandardCharsets.UTF_8), IdUtil.fastSimpleUUID());
                } catch (Exception e) {
                    log.error("boxShelfLocationMsg库位调整异常:{}", e);
                    throw new UtilException(e);
                }
            }
        }
    }

    /**
     * 根据数据类型以及商品获取单据
     *
     * @param dataType
     * @param saleOrder
     * @param saleOrderDetail
     * @return void
     * @author yw
     * @date 2023-09-28 10:22:28
     */
    @Override
    public WarehousingEntry selectBySaleOrder(String dataType, SaleOrder saleOrder, SaleOrderDetail saleOrderDetail) {
        if (StrUtil.hasEmpty(dataType, saleOrderDetail.getSpuId(), saleOrderDetail.getSkuCode())) {
            throw new UtilException("参数为空");
        }
        //不传买家信息
        if (!StrUtil.isEmpty(saleOrder.getMemberCode())) {
            return super.getOne(Wrappers.<WarehousingEntry>lambdaQuery().eq(WarehousingEntry::getEntryCode, saleOrder.getSaleOrderCode()).eq(WarehousingEntry::getDataType, com.lvy.hczn.front.common.constant.Constants.WAREHOUSING_ENTRY_DATA_TYPE_EIGHT).eq(WarehousingEntry::getMemberCode, saleOrder.getMemberCode()).eq(WarehousingEntry::getSpuId, saleOrderDetail.getSpuId()).eq(WarehousingEntry::getSkuCode, saleOrderDetail.getSkuCode()).orderByDesc(BaseModel::getCreateTime).last("limit 1"));
        } else {
            //不传买家信息的时候，就取仓库保质期最近的，因为分拣下架的也是取保质期最近的，会存在一个问题，原先保质期刚好分拣完的时候，生产日期，保质期会对不上
            WarehousingEntry entryInfo = new WarehousingEntry();
            if (!StrUtil.isEmpty(saleOrder.getSaleOrderCode())) {
                entryInfo.setEntryCode(saleOrder.getSaleOrderCode());
            }
            entryInfo.setDataTypeList(com.lvy.hczn.front.common.constant.Constants.entryDataTypeList());
            entryInfo.setSpuId(saleOrderDetail.getSpuId());
            entryInfo.setSkuCode(saleOrderDetail.getSkuCode());
            List<WarehousingEntry> warehousingEntryList = selectOneByCondition(entryInfo, 1);
            if (!warehousingEntryList.isEmpty()) {
                return warehousingEntryList.get(0);
            }
        }
        return null;
    }

    /**
     * 生产日期等基本数据初始化
     *
     * @param warehousingEntry
     * @return void
     * @author yw
     * @date 2023-09-24 21:22:15
     */
    @Override
    public void initBaseData(WarehousingEntry warehousingEntry, String entryBatchCode) {
        WarehousingEntry entryInfo = new WarehousingEntry();
        if (!StrUtil.isEmpty(entryBatchCode)) {
            entryInfo.setEntryCode(entryBatchCode);
        }
        entryInfo.setDataTypeList(com.lvy.hczn.front.common.constant.Constants.entryDataTypeList());
        entryInfo.setSpuId(warehousingEntry.getSpuId());
        entryInfo.setSkuCode(warehousingEntry.getSkuCode());

        //没货箱，则获取仓库最后一次入库的原料批次
        List<WarehousingEntry> entryList = this.selectOneByCondition(entryInfo, 1);
        if (!entryList.isEmpty()) {
            WarehousingEntry model = entryList.get(0);
            warehousingEntry.setSupplierCode(model.getSupplierCode());
            warehousingEntry.setProducerId(model.getProducerId());
            warehousingEntry.setWarrantyDate(model.getWarrantyDate());
            warehousingEntry.setPickTime(model.getPickTime());
            if (warehousingEntry.getPickTime() != null && warehousingEntry.getWarrantyDate() != null) {
                warehousingEntry.setShelfLife(warehousingEntry.getPickTime().plusDays(warehousingEntry.getWarrantyDate()));
            }
            if (StrUtil.isEmpty(warehousingEntry.getBatchCode())) {
                warehousingEntry.setBatchCode(model.getBatchCode());
            }
            warehousingEntry.setBoxCode(model.getBoxCode());
        } else {
            throw new UtilException("当前商品无入库记录，不能缺货");
        }
    }

    /**
     * 原料箱变空箱，库位变更通知(单个货箱)
     *
     * @param goodsBox
     * @param isWarehouse
     * @return void
     * @author yw
     * @date 2023-09-27 10:47:22
     */
    @Override
    public void boxShelfLocationMsgSingle(GoodsBox goodsBox, boolean isWarehouse) {
        List<GoodsBox> arrayList = new ArrayList<>();
        arrayList.add(goodsBox);
        boxShelfLocationMsg(null, arrayList, isWarehouse);
    }

    /**
     * 初始化出入库单库位
     *
     * @param goodsBox
     * @param locationGoodsBoxDtos
     * @return void
     * @author yw
     * @date 2023-09-27 11:51:25
     */
    public void initShelfLocationGoodsBoxDto(GoodsBox goodsBox, List<ShelfLocationGoodsBoxDto> locationGoodsBoxDtos, String spuId) {
        ShelfLocationGoodsBoxDto goodsBoxDto = new ShelfLocationGoodsBoxDto();
        goodsBoxDto.setBoxCode(goodsBox.getBoxCode());
        goodsBoxDto.setBoxSpecId(goodsBox.getGoodsBoxSpecId());
        goodsBoxDto.setIntStorage(goodsBox.isIntStorage());
        goodsBoxDto.setStatus(0);
        if (spuId != null) {
            Spu spu = spuService.getById(spuId);
            if (spu != null) {
                goodsBox.setTemperatureZoneCode(spu.getTemperatureZoneCode());
                goodsBox.setActTemperatureCode(String.valueOf(spu.getTemperatureZoneCode()));
            }
        }
        TemperatureZone temperatureZone = temperatureZoneService.getOne(Wrappers.<TemperatureZone>lambdaQuery().eq(TemperatureZone::getTemperatureZoneCode, goodsBox.getActTemperatureCode()).last("limit 1"));
        if (temperatureZone == null) {
            temperatureZone = temperatureZoneService.getOne(Wrappers.<TemperatureZone>lambdaQuery().eq(TemperatureZone::getTemperatureZoneCode, goodsBox.getTemperatureZoneCode()).last("limit 1"));
        }
        if (temperatureZone != null) {
            goodsBoxDto.setTemperatureId(temperatureZone.getId());
            locationGoodsBoxDtos.add(goodsBoxDto);
        }
    }

    /**
     * 调拨，调拨分拣出入库单
     *
     * @param mapSpec
     * @param entryDtoList
     * @return void
     * @author yw
     * @date 2023-08-18 11:20:50
     */
    public void initData(LinkedHashMap<String, List<WarehousingEntryDto>> mapSpec, List<WarehousingEntryDto> entryDtoList, Map<String, Object> objectMap) {
        mapSpec.forEach((mapSpecKey, mapSpecValue) -> {
            if (!mapSpecValue.isEmpty()) {
                //生产日期分组
                LinkedHashMap<LocalDateTime, List<WarehousingEntryDto>> mapProductDate = mapSpecValue.stream().collect(Collectors.groupingBy(WarehousingEntryDto::getPickTime, LinkedHashMap::new, Collectors.toList()));
                mapProductDate.forEach((key, value) -> {
                    //入库单以规格列表展示，即：以一个仓库下的一个运输/配送单下的一个供应商的一个商品的一个规格，区分货箱列表展示（规格下的存放的哪几个货箱）
                    WarehousingEntryDto dto = mapProductDate.get(key).get(0);
                    Spu spu = spuService.getById(dto.getSpuId());
                    if (spu == null) {
                        throw new UtilException("商品信息为空");
                    }
                    objectMap.put("dataType", dto.getDataType());
                    dto.setSpuCode(spu.getSpuCode());
                    dto.setSkuCode(dto.getSkuCode());
                    dto.setSpecId(dto.getSpecCode());
                    dto.setSupplierId(dto.getSupplierCode());
                    dto.setStorageTime(dto.getCreateTime());
                    //平台的specId出入库单是传skuCode
                    dto.setSpecCode(dto.getSkuCode());
                    dto.setSpecId(dto.getSkuCode());
                    TemperatureZone temperatureZone = temperatureZoneService.getOne(Wrappers.<TemperatureZone>lambdaQuery().eq(TemperatureZone::getTemperatureZoneCode, spu.getTemperatureZoneCode()).last("limit 1"));
                    if (temperatureZone == null) {
                        throw new UtilException("温区信息为空");
                    }
                    dto.setTemperAreaId(String.valueOf(temperatureZone.getId()));
                    dto.setType(dto.getServiceType());
                    dto.setAssociatedOrderCode(dto.getAssociatedOrderCode());
                    dto.setProductionDate(dto.getPickTime());
                    dto.setShelfLife(dto.getWarrantyDate());

                    /**同一个货箱商品数量累加,即：同一个商品同一个sku同一个货箱的数量和重量累加**/
                    List<WarehousingEntryBoxDto> dtoList = new ArrayList<>();
                    LinkedHashMap<String, List<WarehousingEntryDto>> mapBoxCode = value.stream().filter(model -> !StrUtil.isEmpty(model.getBoxCode())).collect(Collectors.groupingBy(WarehousingEntryDto::getBoxCode, LinkedHashMap::new, Collectors.toList()));
                    mapBoxCode.forEach((boxCode, list) -> {
                        WarehousingEntryBoxDto warehousingEntryBoxDto = new WarehousingEntryBoxDto();
                        warehousingEntryBoxDto.setQuantity(BigDecimal.ZERO);
                        warehousingEntryBoxDto.setWeight(BigDecimal.ZERO);
                        warehousingEntryBoxDto.setBoxCode(boxCode);
                        list.forEach(entry -> {
                            warehousingEntryBoxDto.setQuantity(warehousingEntryBoxDto.getQuantity().add(entry.getQuantity()));
                            warehousingEntryBoxDto.setWeight(warehousingEntryBoxDto.getWeight().add(entry.getWeight()));
                        });
                        dtoList.add(warehousingEntryBoxDto);
                    });

                    /**只算到sku,即分拣一份生成一条入库单，然后直接发到平台**/
                /*mapSpecValue.forEach(specWarehouse -> {
                    WarehousingEntryBoxDto warehousingEntryBoxDto = new WarehousingEntryBoxDto();
                    warehousingEntryBoxDto.setQuantity(specWarehouse.getQuantity());
                    warehousingEntryBoxDto.setBoxCode(specWarehouse.getBoxCode());
                    warehousingEntryBoxDto.setWeight(specWarehouse.getWeight());
                    dtoList.add(warehousingEntryBoxDto);
                });*/

                    //异常货箱查询
                    selectExceptionBoxList(dto);

                    dto.setBoxCode(null);
                    dto.setBoxNum(null);
                    dto.setDataType(null);
                    dto.setServiceCode(null);
                    dto.setServiceType(null);
                    dto.setSupplierId(null);
                    dto.setWarrantyDate(null);
                    //规格下的存放的货箱列表，即一个规格存放的N个货箱内
                    dto.setEntryBoxDtoList(dtoList);

                    //以规格为列表展示
                    entryDtoList.add(dto);
                });

            }
        });
    }

    /**
     * 获取异常货箱信息列表
     *
     * @param dto
     * @return void
     * @author yw
     * @date 2023-09-24 16:24:21
     */
    public void selectExceptionBoxList(WarehousingEntryDto dto) {
        WarehousingEntryDto warehousingEntryDto = new WarehousingEntryDto();
        warehousingEntryDto.setAssociatedOrderCode(dto.getAssociatedOrderCode());
        warehousingEntryDto.setServiceCode(dto.getServiceCode());
        warehousingEntryDto.setDataType(com.lvy.hczn.front.common.constant.Constants.WAREHOUSING_ENTRY_DATA_TYPE_SIX);
        List<DataExceptionDetail> list = dataExceptionDetailService.selectListByCodes(warehousingEntryDto);
        if (!list.isEmpty()) {
            //数据组装：缺失和异常都会生成异常记录，即两条记录，需要根据货箱分组，然后类型分组
            List<ExceptionBoxDto> boxDtoList = new ArrayList<>();
            //根据货箱编号分组
            LinkedHashMap<String, List<DataExceptionDetail>> map = list.stream().filter(item -> !StrUtil.isEmpty(item.getBoxCode())).collect(Collectors.groupingBy(DataExceptionDetail::getBoxCode, LinkedHashMap::new, Collectors.toList()));
            map.forEach((k, v) -> {
                //根据类型分组
                LinkedHashMap<Integer, List<DataExceptionDetail>> mapType = v.stream().filter(item -> item.getType() != null).collect(Collectors.groupingBy(DataExceptionDetail::getType, LinkedHashMap::new, Collectors.toList()));
                mapType.forEach((key, value) -> {
                    ExceptionBoxDto exceptionBoxDto = new ExceptionBoxDto();
                    exceptionBoxDto.setBoxCode(k);
                    exceptionBoxDto.setExpType(key);
                    BigDecimal totalWeight = list.stream().map(DataExceptionDetail::getPurchaseWeight).reduce(BigDecimal.ZERO, BigDecimal::add);
                    exceptionBoxDto.setWeight(totalWeight);
                    exceptionBoxDto.setWmsWeight(totalWeight);
                    boxDtoList.add(exceptionBoxDto);
                });
            });
            if (!boxDtoList.isEmpty()) {
                dto.setEntryBoxExpList(boxDtoList);
                DataException dataException = new DataException();
                dataException.setId(list.get(0).getDataExceptionId());
                dataException.setSync(true);
                dataExceptionService.updateById(dataException);
            }
        }
    }

    /**
     * 销售分拣出库单，分拣一份会生产一条记录，出库单推送到平台是，需整合
     *
     * @param mapSpec
     * @param entryDtoList
     * @return void
     * @author yw
     * @date 2023-08-18 11:22:09
     */
    public void initDataSaleSort(LinkedHashMap<String, List<WarehousingEntryDto>> mapSpec, List<WarehousingEntryDto> entryDtoList) {

    }

    /**
     * 提交入库单到平台(初始化值)
     *
     * @param param
     * @return void
     * @author yw
     * @date 2023-06-26 19:17:51
     */
    @Override
    public void commitToPlatformInfo(Param param, String dataType, boolean sortDone) {
        if (param == null) {
            throw new UtilException("参数信息为空");
        }
        /*if (StrUtil.isEmpty(dataType)) {
            throw new UtilException("数据类型为空");
        }*/
        if (!StrUtil.isEmpty(param.getDeliveryOrderCode())) {
            WarehousingEntry warehousingEntry = new WarehousingEntry();
//            warehousingEntry.setBatchCode(param.getDeliveryOrderCode());
            warehousingEntry.setDataType(dataType);
            warehousingEntry.setEntryCode(param.getDeliveryOrderCode());
            warehousingEntry.setServiceCode(param.getPurchaseOrderCode());
            this.commitToPlatform(warehousingEntry, sortDone, false);
        }
    }

    /**
     * 根据配送单，业务单，商品，sku,规格，等查询
     *
     * @param warehousingEntry
     * @param pageNum          为null则无limit
     * @return
     * @author yw
     * @date 2023-09-24 20:47:08
     */
    @Override
    public List<WarehousingEntry> selectOneByCondition(WarehousingEntry warehousingEntry, Integer pageNum) {

        LambdaQueryWrapper<WarehousingEntry> lambdaQueryWrapper = new LambdaQueryWrapper();
        if (!StrUtil.isEmpty(warehousingEntry.getEntryCode())) {
            lambdaQueryWrapper.eq(WarehousingEntry::getEntryCode, warehousingEntry.getEntryCode());
        }
        if (!StrUtil.isEmpty(warehousingEntry.getServiceCode())) {
            lambdaQueryWrapper.eq(WarehousingEntry::getServiceCode, warehousingEntry.getServiceCode());
        }

        if (!StrUtil.isEmpty(warehousingEntry.getSpuId())) {
            lambdaQueryWrapper.eq(WarehousingEntry::getSpuId, warehousingEntry.getSpuId());
        }
        if (!StrUtil.isEmpty(warehousingEntry.getSkuCode())) {
            lambdaQueryWrapper.eq(WarehousingEntry::getSkuCode, warehousingEntry.getSkuCode());
        }
        if (!StrUtil.isEmpty(warehousingEntry.getSpecCode())) {
            lambdaQueryWrapper.eq(WarehousingEntry::getSpecCode, warehousingEntry.getSpecCode());
        }
        if (!StrUtil.isEmpty(warehousingEntry.getSupplierCode())) {
            lambdaQueryWrapper.eq(WarehousingEntry::getSupplierCode, warehousingEntry.getSupplierCode());
        }
        if (!StrUtil.isEmpty(warehousingEntry.getProducerId())) {
            lambdaQueryWrapper.eq(WarehousingEntry::getProducerId, warehousingEntry.getProducerId());
        }
        if (warehousingEntry.getWarrantyDate() != null && warehousingEntry.getWarrantyDate() != 0) {
            lambdaQueryWrapper.eq(WarehousingEntry::getWarrantyDate, warehousingEntry.getWarrantyDate());
        }
        if (warehousingEntry.getPickTime() != null) {
            lambdaQueryWrapper.le(WarehousingEntry::getPickTime, warehousingEntry.getPickTime());
        }

        if (!StrUtil.isEmpty(warehousingEntry.getMemberCode())) {
            lambdaQueryWrapper.eq(WarehousingEntry::getMemberCode, warehousingEntry.getMemberCode());
        }

        if (!StrUtil.isEmpty(warehousingEntry.getDataType())) {
            lambdaQueryWrapper.eq(WarehousingEntry::getDataType, warehousingEntry.getDataType());
        } else {
            if (warehousingEntry.getDataTypeList() != null && !warehousingEntry.getDataTypeList().isEmpty()) {
                lambdaQueryWrapper.in(WarehousingEntry::getDataType, warehousingEntry.getDataTypeList());
            }
        }
        lambdaQueryWrapper.orderByDesc(BaseModel::getCreateTime);
        if (pageNum != null) {
            lambdaQueryWrapper.last("limit " + pageNum);
        }
        return super.list(lambdaQueryWrapper);
    }
}
